{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f34864b5",
   "metadata": {},
   "source": [
    "# Requests\n",
    "\n",
    "The web contains a lot of information that LLMs do not have access to. In order to easily let LLMs interact with that information, we provide a wrapper around the Python Requests module that takes in a URL and fetches data from that URL."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8a84d1fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install --upgrade --quiet langchain-community"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5d8764ba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[RequestsGetTool(requests_wrapper=TextRequestsWrapper(headers=None, aiosession=None, auth=None, response_content_type='text', verify=True), allow_dangerous_requests=True),\n",
       " RequestsPostTool(requests_wrapper=TextRequestsWrapper(headers=None, aiosession=None, auth=None, response_content_type='text', verify=True), allow_dangerous_requests=True),\n",
       " RequestsPatchTool(requests_wrapper=TextRequestsWrapper(headers=None, aiosession=None, auth=None, response_content_type='text', verify=True), allow_dangerous_requests=True),\n",
       " RequestsPutTool(requests_wrapper=TextRequestsWrapper(headers=None, aiosession=None, auth=None, response_content_type='text', verify=True), allow_dangerous_requests=True),\n",
       " RequestsDeleteTool(requests_wrapper=TextRequestsWrapper(headers=None, aiosession=None, auth=None, response_content_type='text', verify=True), allow_dangerous_requests=True)]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_community.agent_toolkits.load_tools import load_tools\n",
    "\n",
    "requests_tools = load_tools([\"requests_all\"], allow_dangerous_tools=True)\n",
    "\n",
    "requests_tools"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "55cfe672",
   "metadata": {},
   "source": [
    "### Inside the tool\n",
    "\n",
    "Each requests tool contains a `requests` wrapper. You can work with these wrappers directly below"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c56d4678",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TextRequestsWrapper(headers=None, aiosession=None, auth=None, response_content_type='text', verify=True)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Each tool wrapps a requests wrapper\n",
    "requests_tools[0].requests_wrapper"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "81aae09e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'<!doctype html><html itemscope=\"\" itemtype=\"http://schema.org/WebPage\" lang=\"en\"><head><meta content=\"Search the world\\'s information, including webpages, images, videos and more. Google has many special features to help you find exactly what you\\'re looking for.\" name=\"description\"><meta content=\"noodp, \" name=\"robots\"><meta content=\"text/html; charset=UTF-8\" http-equiv=\"Content-Type\"><meta content=\"/images/branding/googleg/1x/googleg_standard_color_128dp.png\" itemprop=\"image\"><title>Google</title><script nonce=\"by8KWCDpfJGbptqAqr4KTA\">(function(){var _g={kEI:\\'FRCDZqbtEKPNkPIPsYSpgA0\\',kEXPI:\\'0,18167,775177,2906997,608,432,7,302122,236535,2872,2891,3926,4423,3405,61296,6397,27869,145701,2,16392,342,23024,6699,28950,12996,57737,2,2,1,24626,2006,8155,23350,8702,13734,9779,45600,17057,36747,3801,2412,1549,28670,3030,15816,1804,7734,18098,9161,12089,476,1156,9711,46651,5211785,891,622,38,5991770,2839759,16,527,242,5,16,4,51,1,47,6,1,20717334,7264126,16673,43886,3,318,4,1281,3,2124363,23029351,8163,4636,8409,6577,1450,2727,5911,3780,24246,24917,11953,10511,2370,4834,1573,2960,10886,884,9590,2478,2211,8183,5933,39356,4140,75,1,10009,8926,2657,3437,1365,1,3,1950,155,1,1,1,2481,13504,1004,6732,6595,4,2539,968,540,3092,206,122,3217,4,3004,10345,3552,1694,2968,1115,409,518,4408,3,85,1224,1009,2,3,2297,56,2121,1814,24,664,4436,791,1401,45,1122,3,1,416,1354,156,423,665,2688,7,1538,2,211,2724,975,709,4618,1704,334,2821,709,683,452,212,14,5657,45,126,339,914,748,317,515,2074,216,107,715,38,2,237,498,1,1140,1489,4,432,279,7,12,622,1458,279,870,46,451,4,267,3,1,816,455,669,46,202,691,1,2,1435,5,243,295,834,642,4,525,767,471,436,867,396,412,1570,4,367,3,93,910,790,6,108,172,1,3,9,275,3,251,26,40,448,51,23,1,3,1,1103,162,2,2636,67,178,289,1826,554,881,402,1032,13,651,119,385,1,3,107,21,2,490,118,125,458,41,427,445,207,213,360,460,1472,1,1421,270,60,456,12,89,1140,181,621,579,39,119,600,5,207,24,292,35,1051,1005,23,73,47,6,948,435,120,4,96,2,44,3,61,325,1789,2,285,39,1138,675,2,130,315,50,36,180,597,781,424,14,1,62,5,253,1043,1,973,2,130,7,21544198,5720,3,980,5,6549,10805,2206,20,390,576,343\\',kBL:\\'z8iO\\',kOPI:89978449};(function(){var a;((a=window.google)==null?0:a.stvsc)?google.kEI=_g.kEI:window.google=_g;}).call(this);})();(function(){google.sn=\\'webhp\\';google.kHL=\\'en\\';})();(function(){\\nvar h=this||self;function l(){return window.google!==void 0&&window.google.kOPI!==void 0&&window.google.kOPI!==0?window.google.kOPI:null};var m,n=[];function p(a){for(var b;a&&(!a.getAttribute||!(b=a.getAttribute(\"eid\")));)a=a.parentNode;return b||m}function q(a){for(var b=null;a&&(!a.getAttribute||!(b=a.getAttribute(\"leid\")));)a=a.parentNode;return b}function r(a){/^http:/i.test(a)&&window.location.protocol===\"https:\"&&(google.ml&&google.ml(Error(\"a\"),!1,{src:a,glmm:1}),a=\"\");return a}\\nfunction t(a,b,c,d,k){var e=\"\";b.search(\"&ei=\")===-1&&(e=\"&ei=\"+p(d),b.search(\"&lei=\")===-1&&(d=q(d))&&(e+=\"&lei=\"+d));d=\"\";var g=b.search(\"&cshid=\")===-1&&a!==\"slh\",f=[];f.push([\"zx\",Date.now().toString()]);h._cshid&&g&&f.push([\"cshid\",h._cshid]);c=c();c!=null&&f.push([\"opi\",c.toString()]);for(c=0;c<f.length;c++){if(c===0||c>0)d+=\"&\";d+=f[c][0]+\"=\"+f[c][1]}return\"/\"+(k||\"gen_204\")+\"?atyp=i&ct=\"+String(a)+\"&cad=\"+(b+e+d)};m=google.kEI;google.getEI=p;google.getLEI=q;google.ml=function(){return null};google.log=function(a,b,c,d,k,e){e=e===void 0?l:e;c||(c=t(a,b,e,d,k));if(c=r(c)){a=new Image;var g=n.length;n[g]=a;a.onerror=a.onload=a.onabort=function(){delete n[g]};a.src=c}};google.logUrl=function(a,b){b=b===void 0?l:b;return t(\"\",a,b)};}).call(this);(function(){google.y={};google.sy=[];google.x=function(a,b){if(a)var c=a.id;else{do c=Math.random();while(google.y[c])}google.y[c]=[a,b];return!1};google.sx=function(a){google.sy.push(a)};google.lm=[];google.plm=function(a){google.lm.push.apply(google.lm,a)};google.lq=[];google.load=function(a,b,c){google.lq.push([[a],b,c])};google.loadAll=function(a,b){google.lq.push([a,b])};google.bx=!1;google.lx=function(){};var d=[];google.fce=function(a,b,c,e){d.push([a,b,c,e])};google.qce=d;}).call(this);google.f={};(function(){\\ndocument.documentElement.addEventListener(\"submit\",function(b){var a;if(a=b.target){var c=a.getAttribute(\"data-submitfalse\");a=c===\"1\"||c===\"q\"&&!a.elements.q.value?!0:!1}else a=!1;a&&(b.preventDefault(),b.stopPropagation())},!0);document.documentElement.addEventListener(\"click\",function(b){var a;a:{for(a=b.target;a&&a!==document.documentElement;a=a.parentElement)if(a.tagName===\"A\"){a=a.getAttribute(\"data-nohref\")===\"1\";break a}a=!1}a&&b.preventDefault()},!0);}).call(this);</script><style>#gbar,#guser{font-size:13px;padding-top:1px !important;}#gbar{height:22px}#guser{padding-bottom:7px !important;text-align:right}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}@media all{.gb1{height:22px;margin-right:.5em;vertical-align:top}#gbar{float:left}}a.gb1,a.gb4{text-decoration:underline !important}a.gb1,a.gb4{color:#00c !important}.gbi .gb4{color:#dd8e27 !important}.gbf .gb4{color:#900 !important}\\n</style><style>body,td,a,p,.h{font-family:arial,sans-serif}body{margin:0;overflow-y:scroll}#gog{padding:3px 8px 0}td{line-height:.8em}.gac_m td{line-height:17px}form{margin-bottom:20px}.h{color:#1967d2}em{font-weight:bold;font-style:normal}.lst{height:25px;width:496px}.gsfi,.lst{font:18px arial,sans-serif}.gsfs{font:17px arial,sans-serif}.ds{display:inline-box;display:inline-block;margin:3px 0 4px;margin-left:4px}input{font-family:inherit}body{background:#fff;color:#000}a{color:#681da8;text-decoration:none}a:hover,a:active{text-decoration:underline}.fl a{color:#1967d2}a:visited{color:#681da8}.sblc{padding-top:5px}.sblc a{display:block;margin:2px 0;margin-left:13px;font-size:11px}.lsbb{background:#f8f9fa;border:solid 1px;border-color:#dadce0 #70757a #70757a #dadce0;height:30px}.lsbb{display:block}#WqQANb a{display:inline-block;margin:0 12px}.lsb{background:url(/images/nav_logo229.png) 0 -261px repeat-x;color:#000;border:none;cursor:pointer;height:30px;margin:0;outline:0;font:15px arial,sans-serif;vertical-align:top}.lsb:active{background:#dadce0}.lst:focus{outline:none}</style><script nonce=\"by8KWCDpfJGbptqAqr4KTA\">(function(){window.google.erd={jsr:1,bv:2034,de:true};\\nvar h=this||self;var k,l=(k=h.mei)!=null?k:1,n,p=(n=h.sdo)!=null?n:!0,q=0,r,t=google.erd,v=t.jsr;google.ml=function(a,b,d,m,e){e=e===void 0?2:e;b&&(r=a&&a.message);d===void 0&&(d={});d.cad=\"ple_\"+google.ple+\".aple_\"+google.aple;if(google.dl)return google.dl(a,e,d,!0),null;b=d;if(v<0){window.console&&console.error(a,b);if(v===-2)throw a;b=!1}else b=!a||!a.message||a.message===\"Error loading script\"||q>=l&&!m?!1:!0;if(!b)return null;q++;d=d||{};b=encodeURIComponent;var c=\"/gen_204?atyp=i&ei=\"+b(google.kEI);google.kEXPI&&(c+=\"&jexpid=\"+b(google.kEXPI));c+=\"&srcpg=\"+b(google.sn)+\"&jsr=\"+b(t.jsr)+\\n\"&bver=\"+b(t.bv);var f=a.lineNumber;f!==void 0&&(c+=\"&line=\"+f);var g=a.fileName;g&&(g.indexOf(\"-extension:/\")>0&&(e=3),c+=\"&script=\"+b(g),f&&g===window.location.href&&(f=document.documentElement.outerHTML.split(\"\\\\n\")[f],c+=\"&cad=\"+b(f?f.substring(0,300):\"No script found.\")));google.ple&&google.ple===1&&(e=2);c+=\"&jsel=\"+e;for(var u in d)c+=\"&\",c+=b(u),c+=\"=\",c+=b(d[u]);c=c+\"&emsg=\"+b(a.name+\": \"+a.message);c=c+\"&jsst=\"+b(a.stack||\"N/A\");c.length>=12288&&(c=c.substr(0,12288));a=c;m||google.log(0,\"\",a);return a};window.onerror=function(a,b,d,m,e){r!==a&&(a=e instanceof Error?e:Error(a),d===void 0||\"lineNumber\"in a||(a.lineNumber=d),b===void 0||\"fileName\"in a||(a.fileName=b),google.ml(a,!1,void 0,!1,a.name===\"SyntaxError\"||a.message.substring(0,11)===\"SyntaxError\"||a.message.indexOf(\"Script error\")!==-1?3:0));r=null;p&&q>=l&&(window.onerror=null)};})();</script></head><body bgcolor=\"#fff\"><script nonce=\"by8KWCDpfJGbptqAqr4KTA\">(function(){var src=\\'/images/nav_logo229.png\\';var iesg=false;document.body.onload = function(){window.n && window.n();if (document.images){new Image().src=src;}\\nif (!iesg){document.f&&document.f.q.focus();document.gbqf&&document.gbqf.q.focus();}\\n}\\n})();</script><div id=\"mngb\"><div id=gbar><nobr><b class=gb1>Search</b> <a class=gb1 href=\"https://www.google.com/imghp?hl=en&tab=wi\">Images</a> <a class=gb1 href=\"https://maps.google.com/maps?hl=en&tab=wl\">Maps</a> <a class=gb1 href=\"https://play.google.com/?hl=en&tab=w8\">Play</a> <a class=gb1 href=\"https://www.youtube.com/?tab=w1\">YouTube</a> <a class=gb1 href=\"https://news.google.com/?tab=wn\">News</a> <a class=gb1 href=\"https://mail.google.com/mail/?tab=wm\">Gmail</a> <a class=gb1 href=\"https://drive.google.com/?tab=wo\">Drive</a> <a class=gb1 style=\"text-decoration:none\" href=\"https://www.google.com/intl/en/about/products?tab=wh\"><u>More</u> &raquo;</a></nobr></div><div id=guser width=100%><nobr><span id=gbn class=gbi></span><span id=gbf class=gbf></span><span id=gbe></span><a href=\"http://www.google.com/history/optout?hl=en\" class=gb4>Web History</a> | <a  href=\"/preferences?hl=en\" class=gb4>Settings</a> | <a target=_top id=gb_70 href=\"https://accounts.google.com/ServiceLogin?hl=en&passive=true&continue=https://www.google.com/&ec=GAZAAQ\" class=gb4>Sign in</a></nobr></div><div class=gbh style=left:0></div><div class=gbh style=right:0></div></div><center><br clear=\"all\" id=\"lgpd\"><div id=\"lga\"><img alt=\"Google\" height=\"92\" src=\"/images/branding/googlelogo/1x/googlelogo_white_background_color_272x92dp.png\" style=\"padding:28px 0 14px\" width=\"272\" id=\"hplogo\"><br><br></div><form action=\"/search\" name=\"f\"><table cellpadding=\"0\" cellspacing=\"0\"><tr valign=\"top\"><td width=\"25%\">&nbsp;</td><td align=\"center\" nowrap=\"\"><input name=\"ie\" value=\"ISO-8859-1\" type=\"hidden\"><input value=\"en\" name=\"hl\" type=\"hidden\"><input name=\"source\" type=\"hidden\" value=\"hp\"><input name=\"biw\" type=\"hidden\"><input name=\"bih\" type=\"hidden\"><div class=\"ds\" style=\"height:32px;margin:4px 0\"><input class=\"lst\" style=\"margin:0;padding:5px 8px 0 6px;vertical-align:top;color:#000\" autocomplete=\"off\" value=\"\" title=\"Google Search\" maxlength=\"2048\" name=\"q\" size=\"57\"></div><br style=\"line-height:0\"><span class=\"ds\"><span class=\"lsbb\"><input class=\"lsb\" value=\"Google Search\" name=\"btnG\" type=\"submit\"></span></span><span class=\"ds\"><span class=\"lsbb\"><input class=\"lsb\" id=\"tsuid_1\" value=\"I\\'m Feeling Lucky\" name=\"btnI\" type=\"submit\"><script nonce=\"by8KWCDpfJGbptqAqr4KTA\">(function(){var id=\\'tsuid_1\\';document.getElementById(id).onclick = function(){if (this.form.q.value){this.checked = 1;if (this.form.iflsig)this.form.iflsig.disabled = false;}\\nelse top.location=\\'/doodles/\\';};})();</script><input value=\"AL9hbdgAAAAAZoMeJdl-EuyCyG18Q3UnIHL6DneTFAmo\" name=\"iflsig\" type=\"hidden\"></span></span></td><td class=\"fl sblc\" align=\"left\" nowrap=\"\" width=\"25%\"><a href=\"/advanced_search?hl=en&amp;authuser=0\">Advanced search</a></td></tr></table><input id=\"gbv\" name=\"gbv\" type=\"hidden\" value=\"1\"><script nonce=\"by8KWCDpfJGbptqAqr4KTA\">(function(){var a,b=\"1\";if(document&&document.getElementById)if(typeof XMLHttpRequest!=\"undefined\")b=\"2\";else if(typeof ActiveXObject!=\"undefined\"){var c,d,e=[\"MSXML2.XMLHTTP.6.0\",\"MSXML2.XMLHTTP.3.0\",\"MSXML2.XMLHTTP\",\"Microsoft.XMLHTTP\"];for(c=0;d=e[c++];)try{new ActiveXObject(d),b=\"2\"}catch(h){}}a=b;if(a==\"2\"&&location.search.indexOf(\"&gbv=2\")==-1){var f=google.gbvu,g=document.getElementById(\"gbv\");g&&(g.value=a);f&&window.setTimeout(function(){location.href=f},0)};}).call(this);</script></form><div id=\"gac_scont\"></div><div style=\"font-size:83%;min-height:3.5em\"><br></div><span id=\"footer\"><div style=\"font-size:10pt\"><div style=\"margin:19px auto;text-align:center\" id=\"WqQANb\"><a href=\"/intl/en/ads/\">Advertising</a><a href=\"/services/\">Business Solutions</a><a href=\"/intl/en/about.html\">About Google</a></div></div><p style=\"font-size:8pt;color:#70757a\">&copy; 2024 - <a href=\"/intl/en/policies/privacy/\">Privacy</a> - <a href=\"/intl/en/policies/terms/\">Terms</a></p></span></center><script nonce=\"by8KWCDpfJGbptqAqr4KTA\">(function(){window.google.cdo={height:757,width:1440};(function(){var a=window.innerWidth,b=window.innerHeight;if(!a||!b){var c=window.document,d=c.compatMode==\"CSS1Compat\"?c.documentElement:c.body;a=d.clientWidth;b=d.clientHeight}\\nif(a&&b&&(a!=google.cdo.width||b!=google.cdo.height)){var e=google,f=e.log,g=\"/client_204?&atyp=i&biw=\"+a+\"&bih=\"+b+\"&ei=\"+google.kEI,h=\"\",k=[],l=window.google!==void 0&&window.google.kOPI!==void 0&&window.google.kOPI!==0?window.google.kOPI:null;l!=null&&k.push([\"opi\",l.toString()]);for(var m=0;m<k.length;m++){if(m===0||m>0)h+=\"&\";h+=k[m][0]+\"=\"+k[m][1]}f.call(e,\"\",\"\",g+h)};}).call(this);})();</script>  <script nonce=\"by8KWCDpfJGbptqAqr4KTA\">(function(){google.xjs={basecomb:\\'/xjs/_/js/k\\\\x3dxjs.hp.en.zYvPhVQQvCg.O/ck\\\\x3dxjs.hp.QNuQMmLLXgc.L.X.O/am\\\\x3dAQAAgAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAGAAHAAAAIABAIAAAAAAAHgAAAAAAAABAAIABCAiAA_EdAYAAWAQAgBc/d\\\\x3d1/ed\\\\x3d1/dg\\\\x3d0/ujg\\\\x3d1/rs\\\\x3dACT90oGbsR9qT71QB9Cz2Gz7BlFT7kp4oA\\',basecss:\\'/xjs/_/ss/k\\\\x3dxjs.hp.QNuQMmLLXgc.L.X.O/am\\\\x3dAQAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIABAIAAAAAAAAAAAAAAAAABAAIABCAg/rs\\\\x3dACT90oGZG0ZsREnCg9-8cuPVUcm9WBw7Aw\\',basejs:\\'/xjs/_/js/k\\\\x3dxjs.hp.en.zYvPhVQQvCg.O/am\\\\x3dAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAGAAHAAAAAAAAAAAAAAAAHgAAAAAAAAAAAAAAAACAA_EdAYAAWAQAgBc/dg\\\\x3d0/rs\\\\x3dACT90oHWuEjyPCBYBGaNekEh4EZolvOY8g\\',excm:[]};})();</script>  <link href=\"/xjs/_/ss/k=xjs.hp.QNuQMmLLXgc.L.X.O/am=AQAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIABAIAAAAAAAAAAAAAAAAABAAIABCAg/d=1/ed=1/rs=ACT90oGZG0ZsREnCg9-8cuPVUcm9WBw7Aw/m=sb_he,d\" rel=\"stylesheet\" nonce=\"by8KWCDpfJGbptqAqr4KTA\">      <script nonce=\"by8KWCDpfJGbptqAqr4KTA\">(function(){var u=\\'/xjs/_/js/k\\\\x3dxjs.hp.en.zYvPhVQQvCg.O/am\\\\x3dAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAGAAHAAAAAAAAAAAAAAAAHgAAAAAAAAAAAAAAAACAA_EdAYAAWAQAgBc/d\\\\x3d1/ed\\\\x3d1/rs\\\\x3dACT90oHWuEjyPCBYBGaNekEh4EZolvOY8g/m\\\\x3dsb_he,d\\';var st=1;var amd=1000;var mmd=0;\\nvar e=this||self,f=function(a){return a};var g;var h=function(a){this.g=a};h.prototype.toString=function(){return this.g+\"\"};var k={};\\nfunction l(a,b){a.src=b instanceof h&&b.constructor===h?b.g:\"type_error:TrustedResourceUrl\";var c,d;(c=(b=(d=(c=(a.ownerDocument&&a.ownerDocument.defaultView||window).document).querySelector)==null?void 0:d.call(c,\"script[nonce]\"))?b.nonce||b.getAttribute(\"nonce\")||\"\":\"\")&&a.setAttribute(\"nonce\",c)};var m=function(){var a=document;var b=\"SCRIPT\";a.contentType===\"application/xhtml+xml\"&&(b=b.toLowerCase());return a.createElement(b)};function n(a){a=a===null?\"null\":a===void 0?\"undefined\":a;if(g===void 0){var b=null;var c=e.trustedTypes;if(c&&c.createPolicy){try{b=c.createPolicy(\"goog#html\",{createHTML:f,createScript:f,createScriptURL:f})}catch(d){e.console&&e.console.error(d.message)}g=b}else g=b}a=(b=g)?b.createScriptURL(a):a;return new h(a,k)};google.ps===void 0&&(google.ps=[]);function p(){var a=u,b=function(){};google.lx=google.stvsc?b:function(){q(a);google.lx=b};google.bx||google.lx()}function r(a,b){b&&l(a,n(b));var c=a.onload;a.onload=function(d){c&&c(d);google.ps=google.ps.filter(function(F){return a!==F})};google.ps.push(a);document.body.appendChild(a)}google.as=r;function q(a){google.timers&&google.timers.load&&google.tick&&google.tick(\"load\",\"xjsls\");var b=m();b.onerror=function(){google.ple=1};b.onload=function(){google.ple=0};google.xjsus=void 0;r(b,a);google.aple=-1;google.psa=!0};function t(a){var b=a.getAttribute(\"jscontroller\");return(b===\"UBXHI\"||b===\"R3fhkb\"||b===\"TSZEqd\")&&a.hasAttribute(\"data-src\")}function w(){for(var a=document.getElementsByTagName(\"img\"),b=0,c=a.length;b<c;b++){var d=a[b];if(d.hasAttribute(\"data-lzy_\")&&Number(d.getAttribute(\"data-atf\"))&1&&!t(d))return!0}return!1}for(var x=document.getElementsByTagName(\"img\"),y=0,z=x.length;y<z;++y){var A=x[y];Number(A.getAttribute(\"data-atf\"))&1&&t(A)&&(A.src=A.getAttribute(\"data-src\"))};var B,C,D,E;function G(){google.xjsu=u;e._F_jsUrl=u;E=function(){p()};B=!1;C=(st===1||st===3)&&!!google.caft&&!w();D=(st===2||st===3)&&!!google.rairicb&&!w()}function H(){B||C||D||(E(),B=!0)}setTimeout(function(){google&&google.tick&&google.timers&&google.timers.load&&google.tick(\"load\",\"xjspls\");G();if(C||D){if(C){var a=function(){C=!1;H()};google.caft(a);window.setTimeout(a,amd)}D&&(a=function(){D=!1;H()},(0,google.rairicb)(a),window.setTimeout(a,mmd))}else E()},0);})();window._ = window._ || {};window._DumpException = _._DumpException = function(e){throw e;};window._s = window._s || {};_s._DumpException = _._DumpException;window._qs = window._qs || {};_qs._DumpException = _._DumpException;(function(){var t=[1,2,0,0,0,83886080,0,655360,67567769,8388644,132096,147456,30,0,402654208,537002512,18739459,291570176,24641536];window._F_toggles = window._xjs_toggles = t;})();function _F_installCss(c){}\\n(function(){google.jl={bfl:0,dw:false,ine:false,ubm:false,uwp:true,vs:false};})();(function(){var pmc=\\'{\\\\x22d\\\\x22:{},\\\\x22sb_he\\\\x22:{\\\\x22agen\\\\x22:false,\\\\x22cgen\\\\x22:false,\\\\x22client\\\\x22:\\\\x22heirloom-hp\\\\x22,\\\\x22dh\\\\x22:true,\\\\x22ds\\\\x22:\\\\x22\\\\x22,\\\\x22fl\\\\x22:true,\\\\x22host\\\\x22:\\\\x22google.com\\\\x22,\\\\x22jsonp\\\\x22:true,\\\\x22msgs\\\\x22:{\\\\x22cibl\\\\x22:\\\\x22Clear Search\\\\x22,\\\\x22dym\\\\x22:\\\\x22Did you mean:\\\\x22,\\\\x22lcky\\\\x22:\\\\x22I\\\\\\\\u0026#39;m Feeling Lucky\\\\x22,\\\\x22lml\\\\x22:\\\\x22Learn more\\\\x22,\\\\x22psrc\\\\x22:\\\\x22This search was removed from your \\\\\\\\u003Ca href\\\\x3d\\\\\\\\\\\\x22/history\\\\\\\\\\\\x22\\\\\\\\u003EWeb History\\\\\\\\u003C/a\\\\\\\\u003E\\\\x22,\\\\x22psrl\\\\x22:\\\\x22Remove\\\\x22,\\\\x22sbit\\\\x22:\\\\x22Search by image\\\\x22,\\\\x22srch\\\\x22:\\\\x22Google Search\\\\x22},\\\\x22ovr\\\\x22:{},\\\\x22pq\\\\x22:\\\\x22\\\\x22,\\\\x22rfs\\\\x22:[],\\\\x22sbas\\\\x22:\\\\x220 3px 8px 0 rgba(0,0,0,0.2),0 0 0 1px rgba(0,0,0,0.08)\\\\x22,\\\\x22stok\\\\x22:\\\\x22MGFc934x08Qb93lxNIdhRo63tyg\\\\x22}}\\';google.pmc=JSON.parse(pmc);})();(function(){var c=function(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}};\\nvar e=this||self;var g,h;a:{for(var k=[\"CLOSURE_FLAGS\"],l=e,n=0;n<k.length;n++)if(l=l[k[n]],l==null){h=null;break a}h=l}var p=h&&h[610401301];g=p!=null?p:!1;var q,r=e.navigator;q=r?r.userAgentData||null:null;function t(a){return g?q?q.brands.some(function(b){return(b=b.brand)&&b.indexOf(a)!=-1}):!1:!1}function u(a){var b;a:{if(b=e.navigator)if(b=b.userAgent)break a;b=\"\"}return b.indexOf(a)!=-1};function v(){return g?!!q&&q.brands.length>0:!1}function w(){return u(\"Safari\")&&!(x()||(v()?0:u(\"Coast\"))||(v()?0:u(\"Opera\"))||(v()?0:u(\"Edge\"))||(v()?t(\"Microsoft Edge\"):u(\"Edg/\"))||(v()?t(\"Opera\"):u(\"OPR\"))||u(\"Firefox\")||u(\"FxiOS\")||u(\"Silk\")||u(\"Android\"))}function x(){return v()?t(\"Chromium\"):(u(\"Chrome\")||u(\"CriOS\"))&&!(v()?0:u(\"Edge\"))||u(\"Silk\")}function y(){return u(\"Android\")&&!(x()||u(\"Firefox\")||u(\"FxiOS\")||(v()?0:u(\"Opera\"))||u(\"Silk\"))};var z=v()?!1:u(\"Trident\")||u(\"MSIE\");y();x();w();var A=typeof Symbol===\"function\"&&typeof Symbol()===\"symbol\",B;B=typeof Symbol===\"function\"&&typeof Symbol()===\"symbol\"?Symbol():void 0;var C=[];(A?function(a,b){a[B]=b}:function(a,b){a.g!==void 0?a.g=b:Object.defineProperties(a,{g:{value:b,configurable:!0,writable:!0,enumerable:!1}})})(C,55);Object.freeze(C);var D=function(){};Object.freeze(new function(){});Object.freeze(new D);Object.freeze(new D);var G=!z&&!w(),H=function(a){if(/-[a-z]/.test(\"ved\"))return null;if(G&&a.dataset){if(y()&&!(\"ved\"in a.dataset))return null;a=a.dataset.ved;return a===void 0?null:a}return a.getAttribute(\"data-\"+\"ved\".replace(/([A-Z])/g,\"-$1\").toLowerCase())};var I=[],J=null;function K(a){a=a.target;var b=performance.now(),f=[],L=f.concat,d=I;if(!(d instanceof Array)){var m=typeof Symbol!=\"undefined\"&&Symbol.iterator&&d[Symbol.iterator];if(m)d=m.call(d);else if(typeof d.length==\"number\")d={next:c(d)};else throw Error(\"b`\"+String(d));for(var E=[];!(m=d.next()).done;)E.push(m.value);d=E}I=L.call(f,d,[b]);if(a&&a instanceof HTMLElement)if(a===J){if(b=I.length>=4)b=(I[I.length-1]-I[I.length-4])/1E3<5;if(b){b=google.getEI(a);a.hasAttribute(\"data-ved\")?f=a?H(a)||\"\":\"\":f=(f=\\na.closest(\"[data-ved]\"))?H(f)||\"\":\"\";f=f||\"\";if(a.hasAttribute(\"jsname\"))a=a.getAttribute(\"jsname\");else{var F;a=(F=a.closest(\"[jsname]\"))==null?void 0:F.getAttribute(\"jsname\")}google.log(\"rcm\",\"&ei=\"+b+\"&tgtved=\"+f+\"&jsname=\"+(a||\"\"))}}else J=a,I=[b]}window.document.addEventListener(\"DOMContentLoaded\",function(){document.body.addEventListener(\"click\",K)});}).call(this);</script></body></html>'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_community.utilities import TextRequestsWrapper\n",
    "\n",
    "requests = TextRequestsWrapper()\n",
    "\n",
    "requests.get(\"https://www.google.com\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b0bf1d0",
   "metadata": {},
   "source": [
    "If you need the output to be decoded from JSON, you can use the ``JsonRequestsWrapper``."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3f27ee3d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "Type - <class 'dict'>\n",
      "\n",
      "Content: \n",
      "```\n",
      "{'count': 5707, 'name': 'jackson', 'age': 38}\n",
      "```\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from langchain_community.utilities.requests import JsonRequestsWrapper\n",
    "\n",
    "requests = JsonRequestsWrapper()\n",
    "\n",
    "\n",
    "rval = requests.get(\"https://api.agify.io/?name=jackson\")\n",
    "\n",
    "print(\n",
    "    f\"\"\"\n",
    "\n",
    "Type - {type(rval)}\n",
    "\n",
    "Content: \n",
    "```\n",
    "{rval}\n",
    "```\n",
    "\n",
    "\"\"\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "52a1aa15",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
